# 仅交互式才加载 starship
if status is-interactive; and type -q starship
    starship init fish | source
end

# 静默 greeting
function fish_greeting
end

# zellij 存在才提供短名
type -q zellij; and abbr -a zj zellij

# set universal+export if unset
function setu --description "set universal VAR VAL if unset"
    test (count $argv) -ne 2; and return 1
    set -l k $argv[1]
    set -l v $argv[2]
    if not set -q $k
        set -Ux $k $v
    end
end

# add to PATH（append 版本，保持列表书写顺序即为优先级从低到高）
function addpath --description "persist & dedupe PATH entries if dir exists"
    for p in $argv
        test -d $p; and fish_add_path -a $p
    end
end

# 环境变量
setu GOROOT /usr/lib/go # 可选：若不想固定，可删
setu GOPATH $HOME/.go
setu NPM_CONFIG_PREFIX $HOME/.npm
setu PNPM_HOME $HOME/.pnpm
setu YARN_HOME $HOME/.yarn
setu BUN_INSTALL $HOME/.bun
setu EDITOR nvim
setu VISUAL nvim

# PATH：不存在的目录会被优雅跳过
addpath \
    $HOME/.local/bin \
    $HOME/.cargo/bin \
    $GOROOT/bin \
    $GOPATH/bin \
    $NPM_CONFIG_PREFIX/bin \
    $PNPM_HOME/global/bin \
    $YARN_HOME/bin \
    $BUN_INSTALL/install/global/bin
